package com.xm.xmds1705083.service.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xm.xm.dto.ResultDto;
import com.xm.xm.dto.SearchDto;
import com.xm.xm.util.ErrorCode;
import com.xm.xm.util.ValidateUtils;
import com.xm.xmds1705083.service.mapper.DuoduoFeedBackMapper;
import com.xm.xmds1705083.service.model.DuoduoFeedBack;
import com.xm.xmds1705083.service.service.DuoduoFeedBackService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 杭州新苗网络科技有限公司
 * @author meihf
 * @date 2017/06/16
 * @description
*/ 
@Service("duoduoFeedBackService")
public class DuoduoFeedBackServiceImpl extends ServiceImpl<DuoduoFeedBackMapper,DuoduoFeedBack> implements DuoduoFeedBackService {

    @Autowired
    DuoduoFeedBackMapper duoduoFeedBackMapper;

    @Override
    public ResultDto submit(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        JSONObject filed = searchDto.getFiled();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
             if (!filed.has("message")){
                  resultDto.setMsg(ErrorCode.E10011);
                  resultDto.setCode(ErrorCode.C10011);
                  return resultDto;
              }else{
                  String message = filed.getString("message");
                  DuoduoFeedBack duoduoFeedBack = new DuoduoFeedBack();
                  duoduoFeedBack.setCreateTime(searchDto.getTime().intValue());
                  duoduoFeedBack.setMessage(message);
                  duoduoFeedBack.setUserId(searchDto.getAppUserId().intValue());
                  int result = duoduoFeedBackMapper.insert(duoduoFeedBack);
                  if (ValidateUtils.isGreaterThan0(result)){
                      resultDto.setMsg("提交成功");
                  }else {
                      resultDto.setMsg(ErrorCode.E11004);
                      resultDto.setCode(ErrorCode.C11004);
                  }
             }
        }catch (RuntimeException e ){
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }
}

